<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/9/8
  Time: 9:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
    <style>
        .option-tips .full-width-97{
            width: 97%;
        }
        .layer-box   .layui-layer-content{
            padding: 10px;
        }
    </style>
</head>
<body>
<expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段" widthClass="full-width-97"/>

<div class="layui-form common-form" lay-filter="layuiadmin-form-paymentChannel" id="layuiadmin-form-paymentChannel"
     style="padding: 20px;">

    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>支付渠道名称</th>
            <th>应用场景</th>
            <th>费率</th>
            <th>结算周期</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${paymentChannels}" var="paymentChannel">
            <tr>
                <td>${paymentChannel.name}</td>
                <td>${paymentChannel.useCase}</td>
                <td>${paymentChannel.payRate}%</td>
                <td>${paymentChannel.settlementCycle}</td>
                <td>${weixinSignStatus!=10&&paymentChannel.type!=2?'微信签约未通过':paymentChannel.verify==true?'<span class="layui-badge layui-bg-green">已开通</span>':'<span class="layui-badge">未开通</span>'}</td>
                <td>
                    <c:if test="${weixinSignStatus==10&&paymentChannel.type==2}">
                    <c:if test="${!paymentChannel.verify}">
                        <a class="app layui-btn layui-btn-warm layui-btn-xs" id="${paymentChannel.id}" lay-event="app">参数配置</a>
                    </c:if>
                    <c:if test="${paymentChannel.verify}">
                        <a class="appInfo layui-btn  layui-btn-xs" id="${paymentChannel.id}" lay-event="app">查看参数</a>
                    </c:if>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>

<%@include file="../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function () {
        var $ = layui.$
            , form = layui.form
            , upload = layui.upload;
    })
    $(".appInfo").click(function () {
        var id = $(this).attr("id");
        var merchantNo="${merchantApplication.merchantNo}";
        $.ajax({
            type: "get",
            url: '<%=basePath%>merchantApplication/getConfig/'+id+'.html?merchantNo='+merchantNo,
            dataType:'json',
            success: function (data) {
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shadeClose: true,
                    skin: 'layer-box',
                    content: " <div class=\"layui-form-item\">\n" +
                        "        <label class=\"layui-form-label\">商户号</label>\n" +
                        "        <div class=\"layui-input-inline\">\n" +
                        "            <input  class=\"layui-input\" type=\"text\" value="+data.merchantNo+">\n" +
                        "        </div>\n" +
                        "    </div>\n" +
                        "    <div class=\"layui-form-item\">\n" +
                        "        <label class=\"layui-form-label\">appId</label>\n" +
                        "        <div class=\"layui-input-inline\">\n" +
                        "            <input  class=\"layui-input\" type=\"text\" value="+data.appId+">\n" +
                        "        </div>\n" +
                        "    </div>\n" +
                        "    <div class=\"layui-form-item\">\n" +
                        "        <label class=\"layui-form-label\">mchId</label>\n" +
                        "        <div class=\"layui-input-inline\">\n" +
                        "            <input class=\"layui-input\" type=\"text\" value="+data.mchId+">\n" +
                        "        </div>\n" +
                        "    </div>\n" +
                        "    <div class=\"layui-form-item\">\n" +
                        "        <label class=\"layui-form-label\">私钥</label>\n" +
                        "        <div class=\"layui-input-inline\">\n" +
                        "            <input class=\"layui-input\" type=\"text\" value="+data.privateKey+">\n" +
                        "        </div>\n" +
                        "    </div>"
                });
            }
        })

    })
    $(".app").click(function () {
        var id = $(this).attr("id");
        var dialog = new UtilClass.LayerDialog({
            title: "配置",
            content: '<%=basePath%>merchantApplication/addConfig/' + id + '.html?' + 'merchantApplicationId=' + "${merchantApplication.id}",
        });
        dialog.layerShow();

    })

    function createSubmit() {

        var layer = layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit(' + submitID + ')', function (data) {
            var formData = data.field;
            /*获取checkbox[name='paymentChannel']的值*/
            var arr = new Array();
            $("input:checkbox[name='paymentChannel']:checked").each(function (i) {
                arr[i] = $(this).attr("value");
            });
            formData.paymentChannel = arr.join(",");
            layer.load(2);
            console.log(formData);
            if (formData.id == "" || formData.id == null) {
                formData.id = null;
                $.ajax({
                    url: "<%=basePath%>merchantApplication/create.html",
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    success: function (data) {
                        layer.closeAll('loading');
                        if (data.success) {
                            layer.msg("创建成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            } else {
                $.ajax({
                    url: "<%=basePath%>merchantApplication/update/" + formData.id + ".html",
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    success: function (data) {
                        layer.closeAll('loading');
                        if (data.success) {
                            layer.msg("修改成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#" + submitID).trigger('click');
    }
</script>
</body>
</html>
